# -*- coding:utf-8 -*-
import webapp2
import jinja2
import gaesession
import random
from BiyiModel.RuobiyiBase import Product as ruobiyiProdcut
jinja_environment = jinja2.Environment(
    loader=jinja2.FileSystemLoader(''))
class Admin(gaesession.BaseSessionHandler):
    def get(self):  
        template = jinja_environment.get_template('templates/admin/index.html');
        self.response.out.write(template.render());
    def post(self):
    	title = self.request.get('producttitle');
    	store = int(self.request.get('productstore'));
    	category = int(self.request.get('productcategory'));
    	image = self.request.get('productimage');
    	clickurl = self.request.get('productclickurl');
    	description = self.request.get('productcontent');
    	product = ruobiyiProdcut();
    	product.title = title;
    	product.store = store;
    	product.category = category;
    	product.image = image;
    	product.clickurl = clickurl;
    	product.description = description;
    	if product.put():
    		template = '''
    			创建成功,<a href="/admin">继续创建</a>
    		''';
    		self.response.out.write(template);
    	else:
    		template = '''
    			创建失败,<a href="/">返回首页</a><br />
    			<a href="/admin">继续创建</a>
    		''';
    		self.response.out.write();

class Product(gaesession.BaseSessionHandler):
	"""docstring for Product"""
	def get(self, arg):
		temp = {'PageTitle': u'若比翼'};
		
routes = [
    webapp2.Route('/admin', handler=Admin, name='admin'),
    webapp2.Route('/admin/list', handler=Product, name='product'),
];
app = webapp2.WSGIApplication(routes,debug=True,config=gaesession.sessionconfig)